package org.example.wumeng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.wumeng.mapper.T_doctorSpecialtyMapper;
import org.example.wumeng.pojo.DoctorSpecialty;
import org.example.wumeng.service.T_doctorSpecialtyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 医家专长分类服务实现类
 */
@Service
public class T_doctorSpecialtyServiceImpl extends ServiceImpl<T_doctorSpecialtyMapper, DoctorSpecialty> implements T_doctorSpecialtyService {

    @Autowired
    private T_doctorSpecialtyMapper doctorSpecialtyMapper;

    /**
     * 获取所有启用的专长分类
     */
    @Override
    public List<DoctorSpecialty> getActiveSpecialties() {
        QueryWrapper<DoctorSpecialty> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 1)
                .orderByAsc("sort_order");
        return list(wrapper);
    }

    /**
     * 创建专长分类
     */
    @Override
    public Long createSpecialty(DoctorSpecialty specialty) {
        // 设置默认状态和排序
        specialty.setStatus(1);
        if (specialty.getSortOrder() == null) {
            specialty.setSortOrder(0);
        }
        save(specialty);
        return specialty.getId();
    }

    /**
     * 更新专长分类
     */
    @Override
    public void updateSpecialty(Long id, DoctorSpecialty specialty) {
        specialty.setId(id);
        updateById(specialty);
    }

    /**
     * 删除专长分类
     */
    @Override
    public void deleteSpecialty(Long id) {
        removeById(id);
    }

    /**
     * 获取专长分类统计
     */
    @Override
    public List<Map<String, Object>> getSpecialtyStatistics() {
        return doctorSpecialtyMapper.getSpecialtyStatistics();
    }
    @Override
    public List<Map<String, Object>> getDoctorsBySpecialty(String specialtyName) {
        return doctorSpecialtyMapper.getDoctorsBySpecialty(specialtyName);
    }
}
